package com.cragon.handler;

import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @Description: 查询调用处理器
 * @Author: ZHOUHAILONG
 * @Date: 2021年03月01日 19:55
 */
public class QueryInvocationHandler implements InvocationHandler {
	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		System.out.println("connect to database...");

		Select annotation = method.getAnnotation(Select.class);
		if (annotation != null) {
			String[] value = annotation.value();
			System.out.println(value[0]);
		}

		Update update = method.getAnnotation(Update.class);
		if (update != null) {
			System.out.println(update.value()[0]);
		}

		return null;
	}
}
